package com.sskj.mine.router;

import android.content.Context;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpHeaders;
import com.lzy.okgo.model.HttpParams;
import com.sskj.mine.component.DaggerUserDataComponent;
import com.sskj.mine.util.LogoutUtil;
import com.sskj.common.base.AppManager;
import com.sskj.common.rxbus2.RxBus;
import com.sskj.common.util.SPUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.RxBusCode;
import com.sskj.lib.SPConfig;
import com.sskj.lib.model.room.UserViewModel;
import com.sskj.lib.router.provider.LogoutProvider;

import javax.inject.Inject;

@Route(path = "/mine/service/logout")
public class LogoutProviderImpl implements LogoutProvider {
    @Inject
    UserViewModel userViewModel;

    @Override
    public void logout() {
        DaggerUserDataComponent.create().inject(this);
        userViewModel.clear();
        SPUtil.clear();
        HttpHeaders commonHeaders = OkGo.getInstance().getCommonHeaders();
        HttpParams commonParams = OkGo.getInstance().getCommonParams();
        commonHeaders.clear();
        commonParams.clear();
        commonHeaders.put("systemType", "ANDROID");
        commonParams.put("systemType", "ANDROID");
        OkGo.getInstance().addCommonHeaders(commonHeaders);
        OkGo.getInstance().addCommonParams(commonParams);
        if (!LogoutUtil.isInLogin) {
            LogoutUtil.isInLogin = true;
            AppManager.getAppManager().finishAllActivity("com.sskj.spk.ui.activity.MainActivity");
            ARouter.getInstance().build(RConfig.MINE_LOGIN).navigation();

        }
    }

    @Override
    public void init(Context context) {

    }
}
